import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_team/model/team_member_data.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/image_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'team_member_controller.dart';

class TeamMemberPage extends GetView<TeamMemberController> {
  const TeamMemberPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: backAppbar(title: "团队成员"),
        body: Container(
          color: Colors.white,
          child: GetBuilder<TeamMemberController>(
            id: 'memberList',
            builder: (controller) => ListView.separated(
                itemBuilder: (context, index) {
                  TeamMemberList memberList = controller.memberList[index];
                  return GestureDetector(
                    onTap: () => Get.toNamed(AppRoutes.memberDetail,
                        arguments: {
                          "memberNo": memberList.doctorNo,
                          "signCount": memberList.manageCount
                        }),
                    child: buildListItem(
                        name: memberList.doctorNick!,
                        title: '',
                        signCount: memberList.manageCount!,
                        isLeader: memberList.isLeader == 0 ? false : true,
                        headUrl: memberList.profilePhoto ?? ""),
                  );
                },
                separatorBuilder: (context, index) => divider(),
                itemCount: controller.memberList.length),
          ),
        ));
  }

  Widget buildListItem(
      {required headUrl,
      required String name,
      required String title,
      required int signCount,
      required bool isLeader}) {
    return ListTile(
      isThreeLine: false,
      leading: Stack(
        children: [
          circleImg(width: 56, raduis: 10, head: headUrl),
          isLeader
              ? Positioned(
                  bottom: 0,
                  child: Container(
                    width: ScreenHelper.width(50),
                    height: ScreenHelper.height(20),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: Color.fromRGBO(253, 219, 120, 1),
                        borderRadius: BorderRadius.circular(4)),
                    child: Text(
                      "团队长",
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          color: Colors.white, fontSize: ScreenHelper.sp(12)),
                    ),
                  ),
                )
              : SizedBox.shrink()
        ],
      ),
      title: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Text(
            '${name}',
            style: TextStyle(
                color: AppTheme.dartTextColor, fontSize: ScreenHelper.sp(16)),
          ),
          SizedBox(
            width: ScreenHelper.width(10),
          ),
        ],
      ),
      subtitle: Container(
        margin: EdgeInsets.only(top: 6),
        child: Row(
          children: [
            Text(
              "签约人数",
              style: TextStyle(
                  color: AppTheme.weakTextColor, fontSize: ScreenHelper.sp(14)),
            ),
            SizedBox(
              width: ScreenHelper.width(10),
            ),
            Text(
              "${signCount}",
              style: TextStyle(
                  color: const Color.fromRGBO(41, 132, 248, 1),
                  fontSize: ScreenHelper.sp(14)),
            )
          ],
        ),
      ),
      trailing: Image.asset(
        "assets/profile/icon_arrow_next.png",
        width: ScreenHelper.width(18),
        package: "basic_common",
      ),
    );
  }
}
